home *** CD-ROM | disk | FTP | other *** search
- VERSION 2.00
- Begin Form frmPerfTest
- BackColor = &H00C0C0C0&
- BorderStyle = 3 'Fixed Double
- Caption = "DB Performance Tester"
- ClientHeight = 6300
- ClientLeft = 705
- ClientTop = 2835
- ClientWidth = 9180
- Height = 6705
- Left = 645
- LinkTopic = "Form1"
- ScaleHeight = 6300
- ScaleWidth = 9180
- Top = 2490
- Width = 9300
- Begin CommandButton cmdExit
- Caption = "Exit"
- Height = 495
- Left = 120
- TabIndex = 21
- Top = 1320
- Width = 1215
- End
- Begin CheckBox chkPassthru
- BackColor = &H00C0C0C0&
- Caption = "Passthru"
- Height = 255
- Left = 7920
- TabIndex = 19
- Top = 840
- Visible = 0 'False
- Width = 1095
- End
- Begin TextBox txtIterations
- Height = 285
- Left = 8850
- TabIndex = 15
- Text = "5"
- Top = 210
- Width = 255
- End
- Begin Frame fraRecordset
- BackColor = &H00C0C0C0&
- Height = 615
- Left = 7800
- TabIndex = 14
- Top = 1200
- Visible = 0 'False
- Width = 1335
- Begin OptionButton optDynaset
- BackColor = &H00C0C0C0&
- Caption = "Dynaset"
- Height = 255
- Left = 105
- TabIndex = 18
- Top = 345
- Width = 1095
- End
- Begin OptionButton optSnapshot
- BackColor = &H00C0C0C0&
- Caption = "Snapshot"
- Height = 255
- Left = 105
- TabIndex = 17
- Top = 105
- Value = -1 'True
- Width = 1095
- End
- End
- Begin Frame fraMethod
- BackColor = &H00C0C0C0&
- Height = 1215
- Left = 6045
- TabIndex = 9
- Top = 600
- Width = 1695
- Begin OptionButton optMethod
- BackColor = &H00C0C0C0&
- Caption = "VBSQL"
- Height = 255
- Index = 0
- Left = 135
- TabIndex = 12
- Top = 120
- Value = -1 'True
- Width = 1215
- End
- Begin OptionButton optMethod
- BackColor = &H00C0C0C0&
- Caption = "ODBC API"
- Height = 255
- Index = 1
- Left = 120
- TabIndex = 11
- Top = 360
- Width = 1215
- End
- Begin OptionButton optMethod
- BackColor = &H00C0C0C0&
- Caption = "Jet (no MDB)"
- Height = 255
- Index = 2
- Left = 120
- TabIndex = 10
- Top = 600
- Width = 1455
- End
- Begin OptionButton optMethod
- BackColor = &H00C0C0C0&
- Caption = "Jet (Attached)"
- Height = 255
- Index = 3
- Left = 120
- TabIndex = 13
- Top = 840
- Width = 1530
- End
- End
- Begin CommandButton cmdTest
- Cancel = -1 'True
- Caption = "Test All"
- Enabled = 0 'False
- Height = 495
- Left = 7770
- TabIndex = 7
- Top = 90
- Width = 855
- End
- Begin ComboBox cboPreBuilt
- FontBold = -1 'True
- FontItalic = 0 'False
- FontName = "MS Sans Serif"
- FontSize = 9.75
- FontStrikethru = 0 'False
- FontUnderline = 0 'False
- Height = 360
- Left = 1440
- Style = 2 'Dropdown List
- TabIndex = 6
- Top = 120
- Width = 4455
- End
- Begin ListBox lstResults
- FontBold = -1 'True
- FontItalic = 0 'False
- FontName = "MS Sans Serif"
- FontSize = 9.75
- FontStrikethru = 0 'False
- FontUnderline = 0 'False
- Height = 1710
- Left = 120
- TabIndex = 4
- Top = 4200
- Width = 8895
- End
- Begin TextBox txtSQL
- FontBold = -1 'True
- FontItalic = 0 'False
- FontName = "MS Sans Serif"
- FontSize = 9.75
- FontStrikethru = 0 'False
- FontUnderline = 0 'False
- Height = 1335
- Left = 1440
- MultiLine = -1 'True
- ScrollBars = 2 'Vertical
- TabIndex = 3
- Top = 480
- Width = 4455
- End
- Begin CommandButton cmdExecute
- Caption = "Test Only:"
- Enabled = 0 'False
- Height = 495
- Left = 6015
- TabIndex = 2
- Top = 105
- Width = 1200
- End
- Begin CommandButton cmdLogoff
- Caption = "Logoff"
- Enabled = 0 'False
- Height = 495
- Left = 120
- TabIndex = 1
- Top = 720
- Width = 1215
- End
- Begin CommandButton cmdLogon
- Caption = "Logon"
- Default = -1 'True
- Height = 495
- Left = 120
- TabIndex = 0
- Top = 120
- Width = 1215
- End
- Begin VBSQL VBSQL1
- Caption = "VBSQL1"
- Height = 255
- Left = 0
- Top = 0
- Visible = 0 'False
- Width = 255
- End
- Begin ListBox lstMsgs
- FontBold = -1 'True
- FontItalic = 0 'False
- FontName = "MS Sans Serif"
- FontSize = 9.75
- FontStrikethru = 0 'False
- FontUnderline = 0 'False
- Height = 2190
- Left = 120
- TabIndex = 5
- Top = 1920
- Width = 8895
- End
- Begin Label Label1
- BackColor = &H00000000&
- BackStyle = 0 'Transparent
- Caption = "x"
- Height = 225
- Left = 8700
- TabIndex = 20
- Top = 255
- Width = 195
- End
- Begin Label lblClipData
- Caption = "lblClipdata"
- Height = 255
- Left = 7440
- TabIndex = 16
- Top = 6000
- Visible = 0 'False
- Width = 1695
- End
- Begin Label lblStatus
- BackColor = &H00C0C0C0&
- FontBold = 0 'False
- FontItalic = 0 'False
- FontName = "MS Sans Serif"
- FontSize = 8.25
- FontStrikethru = 0 'False
- FontUnderline = 0 'False
- Height = 255
- Left = 0
- TabIndex = 8
- Top = 6000
- Width = 7455
- End
- Option Explicit
- ' Time Counters
- Dim lExecTime As Long, lFetchTime As Long
- ' VBSQL SQL Connection Handle
- Dim iSQLConn As Integer
- ' ODBC API Enviornment, Database, and Statement Handles
- Dim henv As Long
- Dim hdbc As Long
- Dim hstmt As Long
- ' VB ODBC (Jet) Database Object
- Dim gDB As Database
- ' Access Attached Table Database Object
- Dim gDBAttached As Database
- ' Access Local Database Object
- Dim gDBAccess As Database
- ' Constants for Option Button Indexes
- Const DBLIB_INDEX% = 0
- Const ODBC_INDEX% = 1
- Const JET_INDEX% = 2
- Const ATTACHED_INDEX% = 3
- Const ACCESS_INDEX% = 4
- ' Used for timing...
- Declare Function GetTickCount Lib "User" () As Long
- Sub Attempt (ResultCode As Integer, ErrorMessage As String)
- ' If ResultCode <> SQL_SUCCESS, then bomb out
- If ResultCode <> SQL_SUCCESS Then
- lstMsgs.AddItem Format$(ResultCode) & " - " & ErrorMessage
- Stop
- End If
- End Sub
- Sub cboPreBuilt_Click ()
- Select Case cboPreBuilt.ListIndex
- Case 0
- txtSQL.Text = Q1_1 & Q1_2 & Q1_3 & Q1_4 & Q1_5
- Case 1
- txtSQL.Text = Q2_1 & Q2_2 & Q2_3 & Q2_4 & Q2_5
- Case 2
- txtSQL.Text = Q3_1 & Q3_2 & Q3_3 & Q3_4 & Q3_5
- Case 3
- txtSQL.Text = Q4_1 & Q4_2 & Q4_3 & Q4_4 & Q4_5
- End Select
- End Sub
- Sub cmdExecute_Click ()
- Dim sMode As String
- Dim db As Database
- MousePointer = 11
- lstResults.Clear
- Select Case Val(fraMethod.Tag)
- Case DBLIB_INDEX
- sMode = "VBSQL"
- lblStatus.Caption = "Executing via " & sMode & "..."
- DoEvents
- Call ExecViaDBLib((txtSQL.Text))
- Case ODBC_INDEX
- sMode = "ODBC API"
- lblStatus.Caption = "Executing via " & sMode & "..."
- DoEvents
- Call ExecViaODBC((txtSQL.Text))
- Case JET_INDEX, ATTACHED_INDEX
- If Val(fraMethod.Tag) = JET_INDEX Then
- sMode = "Jet"
- Set db = gDB
- Else
- sMode = "Jet Attached"
- Set db = gDBAttached
- End If
- sMode = sMode & IIf(chkPassthru.Value, " w/ Passthru", "")
- sMode = sMode & IIf(optSnapshot.Value, " Snapshot", " Dynaset")
- lblStatus.Caption = "Executing via " & sMode & "..."
- DoEvents
- If optSnapshot.Value Then
- Call ExecViaJetSnapshot(db, (txtSQL.Text), chkPassthru.Value = 1)
- Else
- Call ExecViaJetDynaset(db, (txtSQL.Text))
- End If
- End Select
- lstMsgs.AddItem Format(lExecTime, "0") & " milliseconds to execute query via " & sMode
- lstMsgs.AddItem Format(lFetchTime, "0") & " milliseconds to fetch results and add to list"
- lblStatus.Caption = ""
- MousePointer = 0
- End Sub
- Sub cmdExit_Click ()
- If cmdLogoff.Enabled Then
- Call cmdLogoff_Click
- End If
- Unload frmPerfTest
- End Sub
- Sub cmdLogoff_Click ()
- ' Logoff VBSQL...
- If iSQLConn <> 0 Then SqlClose iSQLConn
- lstMsgs.AddItem "Closed VBSQL Connection"
- ' Logoff ODBC...
- If hstmt <> 0 Then Attempt SQLFreeStmt(hstmt, 0), "Unable to free statment handle"
- If hdbc <> 0 Then Attempt SQLDisconnect(hdbc), "Unable to disconnect"
- If hdbc <> 0 Then Attempt SQLFreeConnect(hdbc), "Unable to free connection handle"
- lstMsgs.AddItem "Freed ODBC Connection"
- ' Logoff Jet...
- gDB.Close
- lstMsgs.AddItem "Closed Jet Database"
- ' Logoff Attached...
- gDBAttached.Close
- lstMsgs.AddItem "Closed Attached Table Database"
- ' Logoff Jet...
- 'gDBAccess.Close
- 'lstMsgs.AddItem "Closed Local Access Database"
- Clipboard.SetText lblClipData.Caption
- lblClipData.Caption = ""
- cmdExecute.Enabled = False
- cmdTest.Enabled = False
- cmdLogon.Enabled = True
- cmdLogoff.Enabled = False
- End Sub
- Sub cmdLogon_Click ()
- Dim iRC As Integer
- Dim sConnect As String
- Dim sConnectBuffer As String
- Dim ilenConnect As Integer
- Dim lTicksStart As Long, lTicksStop As Long
- Dim sClipData As String
- ' Start keeping track of stats in label...
- lblClipData.Caption = "Task" & Chr$(9) & "VBSQL" & Chr$(9) & "ODBC API" & Chr$(9) & "Jet w/ Passthru" & Chr$(9) & "Jet SS" & Chr$(9) & "Jet DS" & Chr$(9) & "Attached SS" & Chr$(9) & "Attached DS" & Chr$(9) & "Access SS" & Chr$(9)
- lblClipData.Caption = lblClipData.Caption & "Access DS" & Chr$(13) & Chr$(10) & "Logon" & Chr$(9)
- MousePointer = 11
- ' Logon via VBSQL
- lblStatus.Caption = "Logging on via VBSQL..."
- DoEvents
- lTicksStart = GetTickCount()
- iSQLConn = SqlOpenConnection(SERVER, USERNAME, PASSWORD, HOSTNAME, APPNAME)
- iRC = SqlUse(iSQLConn, DBNAME)
- lTicksStop = GetTickCount()
- lstMsgs.AddItem Format(lTicksStop - lTicksStart, "#") & " milliseconds to logon via VBSQL"
- lblClipData.Caption = lblClipData.Caption & Format(lTicksStop - lTicksStart, "#") & Chr$(9)
- ' Logon via ODBC API...
- lblStatus.Caption = "Logging on via ODBC..."
- DoEvents
- lTicksStart = GetTickCount()
- iRC = SQLAllocConnect(henv, hdbc)
- If iRC <> SQL_SUCCESS Then
- MsgBox "Can't allocate ODBC connection handle.", 16
- Stop
- Else
- sConnect = "DSN=" & DSN & ";UID=" & USERNAME & ";PWD=" & PASSWORD & ";DATABASE=" & DBNAME
- sConnect = sConnect & ";WSID=" & HOSTNAME & ";APP=" & APPNAME
- sConnectBuffer = Space$(256)
- iRC = SQLDriverConnect(hdbc, Me.hWnd, sConnect, Len(sConnect), sConnectBuffer, Len(sConnectBuffer), ilenConnect, SQL_DRIVER_NOPROMPT)
- If iRC <> SQL_SUCCESS And iRC <> SQL_SUCCESS_WITH_INFO Then
- DescribeError hdbc, 0
- Stop
- Else
- If iRC = SQL_SUCCESS_WITH_INFO Then DescribeError hdbc, 0
- iRC = SQLAllocStmt(hdbc, hstmt)
- If iRC <> SQL_SUCCESS Then
- MsgBox "Cannot allocate statment handle", 16
- Stop
- End If
- End If
- End If
- lTicksStop = GetTickCount()
- lstMsgs.AddItem Format(lTicksStop - lTicksStart, "#") & " milliseconds to logon via ODBC API"
- ' Add the following line back to use asynchronous calls to SQLExecDirect - see also ExecViaODBC
- ' Attempt SQLSetStmtOption(hstmt, SQL_ASYNC_ENABLE, 1&), "Can't set Async on"
- lblClipData.Caption = lblClipData.Caption & Format(lTicksStop - lTicksStart, "#") & Chr$(9)
- ' Logon via VB ODBC (Jet)...
- lblStatus.Caption = "Logging on via Jet..."
- DoEvents
- lTicksStart = GetTickCount()
- sConnect = "ODBC;"
- sConnect = sConnect & "DSN=" & DSN & ";UID=" & USERNAME & ";PWD=" & PASSWORD & ";DATABASE=" & DBNAME
- sConnect = sConnect & ";WSID=" & HOSTNAME & ";APP=" & APPNAME
- Set gDB = OpenDatabase("", False, True, sConnect)
- lTicksStop = GetTickCount()
- lstMsgs.AddItem Format(lTicksStop - lTicksStart, "#") & " milliseconds to logon via Jet"
- lblClipData.Caption = lblClipData.Caption & Format(lTicksStop - lTicksStart, "#") & Chr$(9)
- lblClipData.Caption = lblClipData.Caption & Format(lTicksStop - lTicksStart, "#") & Chr$(9)
- lblClipData.Caption = lblClipData.Caption & Format(lTicksStop - lTicksStart, "#") & Chr$(9)
- ' Logon to Access Attached Table Database...
- lblStatus.Caption = "Logging on to Access Attached Tables Database..."
- DoEvents
- lTicksStart = GetTickCount()
- ' This is an Access MDB with attached table connections to the same
- ' SQL Server tables...
- Set gDBAttached = OpenDatabase(JETDB, False, True)
- lTicksStop = GetTickCount()
- lstMsgs.AddItem Format(lTicksStop - lTicksStart, "#") & " milliseconds to logon to Access Attached Tables Database"
- lblClipData.Caption = lblClipData.Caption & Format(lTicksStop - lTicksStart, "#") & Chr$(9)
- lblClipData.Caption = lblClipData.Caption & Format(lTicksStop - lTicksStart, "#") & Chr$(9)
- lblClipData.Caption = lblClipData.Caption & Chr$(13) & Chr$(10)
- lblStatus.Caption = ""
- MousePointer = 0
- cmdExecute.Enabled = True
- cmdTest.Enabled = True
- cmdLogon.Enabled = False
- cmdLogoff.Enabled = True
- End Sub
- Sub cmdTest_Click ()
- Dim iCount As Integer
- Dim lExecSum As Long
- Dim lFetchSum As Long
- Dim iNum As Integer
- iNum = Val(txtIterations.Text)
- If iNum < 1 Or iNum > 9 Then Exit Sub
- MousePointer = 11
- lblClipData.Caption = lblClipData.Caption & txtSQL.Text & Chr$(9)
- DBLib:
- For iCount = 1 To iNum
- lblStatus.Caption = "Executing VBSQL Iteration" & Str$(iCount)
- lstResults.Clear
- DoEvents
- Call ExecViaDBLib((txtSQL.Text))
- lExecSum = lExecSum + lExecTime
- lFetchSum = lFetchSum + lFetchTime
- Next iCount
- lstMsgs.AddItem Format(lExecSum / iNum, "0") & " average milliseconds to execute query via VBSQL"
- lstMsgs.AddItem Format(lFetchSum / iNum, "0") & " average milliseconds to fetch results and add to list"
- lblClipData.Caption = lblClipData.Caption & Format(((lExecSum / iNum) + (lFetchSum / iNum)), "0") & Chr$(9)
- lExecSum = 0
- lFetchSum = 0
- ODBC:
- For iCount = 1 To iNum
- lblStatus.Caption = "Executing ODBC API Iteration" & Str$(iCount)
- lstResults.Clear
- DoEvents
- Call ExecViaODBC((txtSQL.Text))
- lExecSum = lExecSum + lExecTime
- lFetchSum = lFetchSum + lFetchTime
- Next iCount
- lstMsgs.AddItem Format(lExecSum / iNum, "0") & " average milliseconds to execute query via ODBC API"
- lstMsgs.AddItem Format(lFetchSum / iNum, "0") & " average milliseconds to fetch results and add to list"
- lblClipData.Caption = lblClipData.Caption & Format(((lExecSum / iNum) + (lFetchSum / iNum)), "0") & Chr$(9)
- JetPassthru:
- For iCount = 1 To iNum
- lblStatus.Caption = "Executing Jet Passthru Iteration" & Str$(iCount)
- lstResults.Clear
- DoEvents
- Call ExecViaJetSnapshot(gDB, (txtSQL.Text), True)
- lExecSum = lExecSum + lExecTime
- lFetchSum = lFetchSum + lFetchTime
- Next iCount
- lstMsgs.AddItem Format(lExecSum / iNum, "0") & " average milliseconds to execute query via Jet Passthru"
- lstMsgs.AddItem Format(lFetchSum / iNum, "0") & " average milliseconds to fetch results and add to list"
- lblClipData.Caption = lblClipData.Caption & Format(((lExecSum / iNum) + (lFetchSum / iNum)), "0") & Chr$(9)
- lExecSum = 0
- lFetchSum = 0
- JetSnapshot:
- For iCount = 1 To iNum
- lblStatus.Caption = "Executing Jet Snapshot Iteration" & Str$(iCount)
- lstResults.Clear
- DoEvents
- Call ExecViaJetSnapshot(gDB, (txtSQL.Text), False)
- lExecSum = lExecSum + lExecTime
- lFetchSum = lFetchSum + lFetchTime
- Next iCount
- lstMsgs.AddItem Format(lExecSum / iNum, "0") & " average milliseconds to execute query via Jet Snapshot"
- lstMsgs.AddItem Format(lFetchSum / iNum, "0") & " average milliseconds to fetch results and add to list"
- lblClipData.Caption = lblClipData.Caption & Format(((lExecSum / iNum) + (lFetchSum / iNum)), "0") & Chr$(9)
- lExecSum = 0
- lFetchSum = 0
- JetDynaset:
- For iCount = 1 To iNum
- lblStatus.Caption = "Executing Jet Dynaset Iteration" & Str$(iCount)
- lstResults.Clear
- DoEvents
- Call ExecViaJetDynaset(gDB, (txtSQL.Text))
- lExecSum = lExecSum + lExecTime
- lFetchSum = lFetchSum + lFetchTime
- Next iCount
- lstMsgs.AddItem Format(lExecSum / iNum, "0") & " average milliseconds to execute query via Jet Dynaset"
- lstMsgs.AddItem Format(lFetchSum / iNum, "0") & " average milliseconds to fetch results and add to list"
- lblClipData.Caption = lblClipData.Caption & Format(((lExecSum / iNum) + (lFetchSum / iNum)), "0") & Chr$(9)
- lExecSum = 0
- lFetchSum = 0
- AttachedSnapshot:
- For iCount = 1 To iNum
- lblStatus.Caption = "Executing Attached Snapshot Iteration" & Str$(iCount)
- lstResults.Clear
- DoEvents
- Call ExecViaJetSnapshot(gDBAttached, (txtSQL.Text), False)
- lExecSum = lExecSum + lExecTime
- lFetchSum = lFetchSum + lFetchTime
- Next iCount
- lstMsgs.AddItem Format(lExecSum / iNum, "0") & " average milliseconds to execute query via Attached Snapshot"
- lstMsgs.AddItem Format(lFetchSum / iNum, "0") & " average milliseconds to fetch results and add to list"
- lblClipData.Caption = lblClipData.Caption & Format(((lExecSum / iNum) + (lFetchSum / iNum)), "0") & Chr$(9)
- lExecSum = 0
- lFetchSum = 0
- AttachedDynaset:
- For iCount = 1 To iNum
- lblStatus.Caption = "Executing Attached Dynaset Iteration" & Str$(iCount)
- lstResults.Clear
- DoEvents
- Call ExecViaJetDynaset(gDBAttached, (txtSQL.Text))
- lExecSum = lExecSum + lExecTime
- lFetchSum = lFetchSum + lFetchTime
- Next iCount
- lstMsgs.AddItem Format(lExecSum / iNum, "0") & " average milliseconds to execute query via Attached Dynaset"
- lstMsgs.AddItem Format(lFetchSum / iNum, "0") & " average milliseconds to fetch results and add to list"
- lblClipData.Caption = lblClipData.Caption & Format(((lExecSum / iNum) + (lFetchSum / iNum)), "0") & Chr$(9)
- lExecSum = 0
- lFetchSum = 0
- GoTo TestExit
- lstMsgs.AddItem Format(lExecSum / iNum, "0") & " average milliseconds to execute query via Access Dynaset"
- lstMsgs.AddItem Format(lFetchSum / iNum, "0") & " average milliseconds to fetch results and add to list"
- lblClipData.Caption = lblClipData.Caption & Format(((lExecSum / iNum) + (lFetchSum / iNum)), "0") & Chr$(9)
- lExecSum = 0
- lFetchSum = 0
- TestExit:
- lblClipData.Caption = lblClipData.Caption & Chr$(13) & Chr$(10)
- lblStatus.Caption = "Done."
- Beep
- MousePointer = 0
- End Sub
- Sub DescribeError (ByVal hdbc As Long, ByVal hstmt As Long)
- ' Print an error message for the given connection handle
- ' and statement handle
- Dim sBuffer1 As String * 16
- Dim sBuffer2 As String * 256
- Dim iOutLen As Integer
- Dim lNative As Long
- Dim iRC As Integer
- sBuffer1 = String$(16, 0)
- sBuffer2 = String$(256, 0)
- iRC = SQLError(0, hdbc, hstmt, sBuffer1, lNative, sBuffer2, 256, iOutLen)
- If iRC = SQL_SUCCESS Or iRC = SQL_SUCCESS_WITH_INFO Then
- If iOutLen = 0 Then
- lstMsgs.AddItem "Error -- No error information available"
- Stop
- Else
- lstMsgs.AddItem Format$(lNative) & " - " & Left$(sBuffer2, iOutLen)
- End If
- End If
- Loop Until iRC <> SQL_SUCCESS
- End Sub
- Sub ExecViaDBLib (sSQL As String)
- Dim rc As Integer
- Dim iCount As Integer
- Dim sStuff As String
- Dim lTicksStart As Long, lTicksStop As Long
- lTicksStart = GetTickCount()
- If SqlCmd(iSQLConn, sSQL) = FAIL Then Exit Sub
- If SqlExec(iSQLConn) = FAIL Then Exit Sub
- lTicksStop = GetTickCount()
- lExecTime = lTicksStop - lTicksStart
- lTicksStart = GetTickCount()
- Do While SqlResults(iSQLConn) <> NOMORERESULTS
- Do While SqlNextRow(iSQLConn) <> NOMOREROWS
- sStuff = ""
- For iCount = 1 To SqlNumCols(iSQLConn)
- sStuff = sStuff & SqlData(iSQLConn, iCount) & Chr$(9)
- Next iCount
- lstResults.AddItem sStuff
- Loop
- Loop
- lTicksStop = GetTickCount()
- lFetchTime = lTicksStop - lTicksStart
- lstResults.Refresh
- End Sub
- Sub ExecViaJetDynaset (db As Database, sSQL As String)
- Dim ss As Dynaset
- Dim rc As Integer
- Dim iCount As Integer
- Dim sStuff As String
- Dim lTicksStart As Long, lTicksStop As Long
- ' Comment out line below if you use passthru...
- If Right(sSQL, 2) = "%'" Then Mid(sSQL, Len(sSQL) - 1, 2) = "*'"
- lTicksStart = GetTickCount()
- Set ss = db.CreateDynaset(sSQL)
- lTicksStop = GetTickCount()
- lExecTime = lTicksStop - lTicksStart
- lTicksStart = GetTickCount()
- Do While Not ss.EOF
- sStuff = ""
- For iCount = 0 To ss.Fields.Count - 1
- sStuff = sStuff & ss(iCount) & Chr$(9)
- Next iCount
- lstResults.AddItem sStuff
- ss.MoveNext
- Loop
- lTicksStop = GetTickCount()
- lFetchTime = lTicksStop - lTicksStart
- lstResults.Refresh
- ss.Close
- End Sub
- Sub ExecViaJetSnapshot (db As Database, sSQL As String, fPassThru As Integer)
- Dim ss As snapshot
- Dim rc As Integer
- Dim iCount As Integer
- Dim sStuff As String
- Dim lTicksStart As Long, lTicksStop As Long
- Dim iPassThrough As Integer
- If fPassThru Then iPassThrough = 64 Else iPassThrough = 0
- ' Comment out line below if you use passthru...
- If Right(sSQL, 2) = "%'" Then Mid(sSQL, Len(sSQL) - 1, 2) = "*'"
- lTicksStart = GetTickCount()
- Set ss = db.CreateSnapshot(sSQL, iPassThrough)
- lTicksStop = GetTickCount()
- lExecTime = lTicksStop - lTicksStart
- lTicksStart = GetTickCount()
- Do While Not ss.EOF
- sStuff = ""
- For iCount = 0 To ss.Fields.Count - 1
- sStuff = sStuff & ss(iCount) & Chr$(9)
- Next iCount
- lstResults.AddItem sStuff
- ss.MoveNext
- Loop
- lTicksStop = GetTickCount()
- lFetchTime = lTicksStop - lTicksStart
- lstResults.Refresh
- ss.Close
- End Sub
- Sub ExecViaODBC (sQuery As String)
- Dim lOutLen As Long
- Dim iCount As Integer
- Dim iNumCols As Integer
- Dim iRC As Integer
- Const iBufferLen% = 256
- Dim sBuffer As String * iBufferLen
- Dim sStuff As String
- Dim lTicksStart As Long, lTicksStop As Long
- lTicksStart = GetTickCount()
- iRC = SQLExecDirect(hstmt, sQuery, Len(sQuery))
- ' Add the following lines back to allow asynchronous execution
- ' Do While iRC = SQL_STILL_EXECUTING
- ' DoEvents
- ' iRC = SQLExecDirect(hstmt, sQuery, Len(sQuery))
- ' Loop
- lTicksStop = GetTickCount()
- lExecTime = lTicksStop - lTicksStart
- If iRC <> SQL_SUCCESS Then
- DescribeError hdbc, hstmt
- Exit Sub
- End If
- lTicksStart = GetTickCount()
- iRC = SQLNumResultCols(hstmt, iNumCols)
- If iRC <> SQL_SUCCESS Then
- DescribeError hdbc, hstmt
- Exit Sub
- End If
- Do While SQLFetch(hstmt) = SQL_SUCCESS
- sStuff = ""
- For iCount = 1 To iNumCols
- Attempt SQLGetData(hstmt, iCount, 1, sBuffer, iBufferLen, lOutLen), "Call to SQLGetData Failed"
- If lOutLen = -1 Then
- sStuff = sStuff & "NULL" & Chr$(9)
- Else
- sStuff = sStuff & Left$(sBuffer, lOutLen) & Chr$(9)
- End If
- Next iCount
- lstResults.AddItem sStuff
- Loop
- lTicksStop = GetTickCount()
- lFetchTime = lTicksStop - lTicksStart
- lstResults.Refresh
- Attempt SQLFreeStmt(hstmt, SQL_CLOSE), "FreeStmt Failed"
- End Sub
- Sub Form_Load ()
- Dim sMsg As String, iRC As Integer
- ' Initialize VBSQL...
- sMsg = SqlInit()
- If sMsg = "" Then
- MsgBox "Can't initialize VBSQL environment.", 16
- Stop
- End If
- ' Initialize ODBC...
- iRC = SQLAllocEnv(henv)
- If iRC <> SQL_SUCCESS Then
- MsgBox "Can't allocate ODBC environment.", 16
- Stop
- End If
- ' Fill combobox with descriptions of test queries
- cboPreBuilt.AddItem Q1Name
- cboPreBuilt.AddItem Q2Name
- cboPreBuilt.AddItem Q3Name
- cboPreBuilt.AddItem Q4Name
- cboPreBuilt.ListIndex = 0
- End Sub
- Sub Form_Unload (Cancel As Integer)
- ' Clean up from VBSQL...
- If iSQLConn <> 0 Then
- SqlWinExit
- SqlExit
- End If
- ' Clean up ODBC
- If henv <> 0 Then
- Attempt SQLFreeEnv(henv), "Couldn't free ODBC environment"
- End If
- End Sub
- Sub optMethod_Click (Index As Integer)
- ' Keep track of selected option in frame's tag
- fraMethod.Tag = CStr(Index)
- ' Turn on/off appropriate options...
- Select Case Index
- Case DBLIB_INDEX
- fraRecordset.Visible = False
- chkPassthru.Visible = False
- Case ODBC_INDEX
- fraRecordset.Visible = False
- chkPassthru.Visible = False
- Case JET_INDEX
- fraRecordset.Visible = True
- chkPassthru.Visible = True
- Case ATTACHED_INDEX
- fraRecordset.Visible = True
- chkPassthru.Visible = False
- chkPassthru.Value = 0
- End Select
- End Sub
- Sub txtIterations_Change ()
- ' limit to one char (1-9)
- If Len(txtIterations.Text) > 1 Then
- txtIterations.Text = Right(txtIterations.Text, 1)
- Beep
- End If
- End Sub
- Sub txtIterations_KeyPress (KeyAscii As Integer)
- ' Only allow numbers 1-9...
- If KeyAscii < 49 Or KeyAscii > 57 Then KeyAscii = 0
- End Sub
- Sub VBSQL1_Error (SqlConn As Integer, Severity As Integer, ErrorNum As Integer, ErrorStr As String, RetCode As Integer)
- lstMsgs.AddItem CStr(ErrorNum) & " - " & ErrorStr
- End Sub
- Sub VBSQL1_Message (SqlConn As Integer, Message As Long, State As Integer, Severity As Integer, MsgStr As String)
- lstMsgs.AddItem CStr(Message) & " - " & MsgStr
- End Sub
-